package com.example.myapplication.fragment.fragment2;

import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.video.video_bean.Video_Bean;
import com.example.myapplication.video.video_sift.Vido_Ziding;
import com.google.android.material.appbar.AppBarLayout;

public class City_Activity extends AppCompatActivity {

    private Vido_Ziding cityVideo;
    private Integer index;
    private RecyclerView cityRec;
    private AppBarLayout cityAppbar;
    private RecyclerView.LayoutParams params;
    private CoordinatorLayout cityCoor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city_);
        index = getIntent().getIntExtra("index", 0);

        initView();
        initData();
    }

    private void initData() {
        cityVideo.setUp(Video_Bean.getPlayUrl(index), true, "");
        cityVideo.startPlayLogic();
        cityAppbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                Log.i("ljl", "onOffsetChanged______" + (verticalOffset / 10));
                params = new RecyclerView.LayoutParams(verticalOffset, verticalOffset);
                if (verticalOffset < 0 && verticalOffset > -1275) {

//                    cityVideo.setLayoutParams(params);


                    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) cityVideo.getLayoutParams();
                    layoutParams.topMargin = verticalOffset*-1;
                    
                    cityVideo.setLayoutParams(layoutParams);

                } else {
                    cityVideo.setScaleX(1);
                    cityVideo.setScaleY(1);
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        cityVideo.release();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    private void initView() {

        cityVideo = (Vido_Ziding) findViewById(R.id.city_video);

//        cityRec = (RecyclerView) findViewById(R.id.city_rec);

        cityAppbar = (AppBarLayout) findViewById(R.id.city_appbar);
        cityCoor = (CoordinatorLayout) findViewById(R.id.city_coor);
    }
}
